Professional ASP.NET MVC 3 by Jon Galloway & Phil Haack & Brad Wilson & K. Scott Allen
Author:Jon Galloway & Phil Haack & Brad Wilson & K. Scott Allen
Language: eng
Format: epub
Publisher: John Wiley & Sons
Published: 2011-07-17T16:00:00+00:00
The tmpl method combines the template with the JSON data to produce real DOM elements. Because the JSON data is an array of artists, the template engine renders the template once for each artist in the array. The code takes the template output and appends the output to the artist list.
Client-side templates are a powerful technology, and this section is only scratching the surface of the template engine features. However, the code is not on par with the behavior of the AJAX helper from earlier in the chapter. If you remember from the “AJAX Helpers” section earlier in the chapter, the AJAX helper had the ability to call a method if the server threw an error. The helper also turned on an animated gif while the request was outstanding. You can implement all these features, too; you just have to remove one level of abstraction.
jQuery.ajax for Maximum Flexibility
When you need complete control over an AJAX request, you can turn to the jQuery ajax method. The ajax method takes an options parameter where you can specify the HTTP verb (such as GET or POST), the timeout, an error handler, and more. All the other asynchronous communication methods you've seen (load and getJSON) ultimately call down to the ajax method.
Using the ajax method, you can achieve all the functionality you had with the AJAX helper and still use client-side templates:
$("#artistSearch").submit(function (event) { event.preventDefault(); var form = $(this); $.ajax({ url: form.attr("action"), data: form.serialize(), beforeSend: function () { $("#ajax-loader").show(); }, complete: function () { $("#ajax-loader").hide(); }, error: searchFailed, success: function (data) { $("#artistTemplate").tmpl(data).appendTo("#artist-list"); } }); });
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12571)
Hello! Python by Anthony Briggs(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8299)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7083)
Microservices with Go by Alexander Shuiskov(6853)
Practical Design Patterns for Java Developers by Miroslav Wengner(6770)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6711)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6417)
Angular Projects - Third Edition by Aristeidis Bampakos(6116)
The Art of Crafting User Stories by The Art of Crafting User Stories(5645)
NetSuite for Consultants - Second Edition by Peter Ries(5578)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5382)
Kotlin in Action by Dmitry Jemerov(5065)
